<template>
	<uv-picker title="客户经理列表" ref="picker" :columns="columns" @close="closeFunc" @confirm="confirmFunc" keyName="name"></uv-picker>
</template>

<script setup>
	import {
		computed,
		watch,
		onMounted,
		getCurrentInstance,
		ref,
		defineEmits
	} from 'vue';
	const {
		proxy: that
	} = getCurrentInstance();
	let props = defineProps({
		show: {
			type: Boolean,
			default: () => {
				return false;
			}
		},
		dataObj: {
			type: Object,
			default: () => {
				return {};
			}
		}
	});
	const emit = defineEmits(['close', 'onSuccess']);

	function closeFunc() {
		emit('close', false);
	}

	function onSuccessFunc() {
		emit('onSuccess', false);
	}

	let columns = ref([]);
	let wxGetAdminList = () => {
		uni.showLoading({
			mask: true
		})
		var obj = {
			page: 1,
			num: 9999,
			keyword: "",
			province_id: "",
			city_id: "",
			county_id: "",
			identity: 1,
			position_id_arr: [2],
		}
		that.$Api.wxGetAdminList(obj).then(res => {
			console.log(res, "客户经理列表")
			uni.hideLoading()
			if (res.code == 200) {
				columns.value.push(res.data.list);
				that.$refs.picker.open();
			}
		}).catch(err => {
			uni.hideLoading()
		})
	}
	onMounted(() => {

	})
	watch(() => props.show, (newValue, oldValue) => {
		console.log(newValue, oldValue, "值变化")
		if (props.show) {
			wxGetAdminList();
		} else {
			columns.value = [];
			that.$refs.picker.close();
		}
	});
	let confirmFunc = (e) => {
		console.log(e)
		that.$Api.assignAccountManager({
			project_id: props.dataObj.id,
			account_manager_id: e.value[0].id,
			remark: ''
		}).then(res => {
			console.log(res, '分配客户经理')
			if (res.code == 200) {
				uni.showToast({
					title: '操作成功',
					icon: 'success'
				})
				onSuccessFunc();
			} else {
				uni.showToast({
					title: res.message,
					icon: 'error'
				})
			}
		}).catch(err => {
			uni.showToast({
				title: err.message,
				icon: 'error'
			})
		})
	}
	// const statusText = computed(() => {

	// });
</script>

<style scoped lang="scss">

</style>